package com.atguigu.mymvc.util;

import com.atguigu.headline.common.Result;
import jakarta.servlet.ServletResponse;

import java.io.IOException;
import java.io.PrintWriter;

public class ResponseUtil {
    public static void print(ServletResponse response , Result result) throws IOException {
        //设置响应编码
        response.setCharacterEncoding("UTF-8");
        //设置MIME-TYPE以及告诉浏览器使用何种编码来解释我
        response.setContentType("application/json;charset=utf-8");
        PrintWriter out = response.getWriter();
        out.println(JsonUtil.toJson(result));
        out.flush();
    }
}
